import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'
import Login from '../views/Login.vue'
import {Toast} from 'vant'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    component: Index,
		children:[
			{
				path:'/home',
				name:'home',
				component:() => import('@/views/tabbar/home.vue')
			},
			{
				path:'/activity',
				name:'activity',
				component:() => import('@/views/tabbar/activity.vue')
			},
			{
				path:'/me',
				name:'me',
				component:() => import('@/views/tabbar/me.vue')
			},
			{
				path:'/shop',
				name:'shop',
				component:() => import('@/views/tabbar/shop.vue')
			}
		]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
	{
		path:'/register',
		name:'register',
		component:() => import('@/views/Register.vue')
	},
	{
		path:'/user-info',
		name:'user-info',
		component:() => import('@/views/me/user-info.vue')
	},
	{
		path:'/user-address',
		name:'user-address',
		component:() => import('@/views/me/user-address.vue')
	},
	{
		path:'/user-address-add',
		name:'user-address-add',
		component:() => import('@/views/me/user-address-add.vue')
	},
	{
		path:'/user-address-edit',
		name:'user-address-edit',
		component:() => import('@/views/me/user-address-edit.vue')
	},
	{
		path:'/user-change-password',
		name:'user-change-password',
		component:() => import('@/views/me/user-change-password.vue')
	},
	{
		path:'/shop-info',
		name:'shop-info',
		component:() => import('@/views/shop/shop-info.vue')
	},
	{
		path:'/shop-order',
		name:'shop-order',
		component:() => import('@/views/shop/shop-order.vue')
	},
	{
		path:'/shop-order-buy-car',
		name:'shop-order-buy-car',
		component:() => import('@/views/shop/shop-order-buy-car.vue')
	},
	{
		path:'/shop-order-team',
		name:'shop-order-team',
		component:() => import('@/views/shop/shop-order-team.vue')
	},
	{
		path:'/shop-order-rush',
		name:'shop-order-rush',
		component:() => import('@/views/shop/shop-order-rush.vue')
	},
	{
		path:'/user-buy-car',
		name:'user-buy-car',
		component:() => import('@/views/me/user-buy-car.vue')
	},
	{
		path:'/user-order',
		name:'user-order',
		component:() => import('@/views/me/user-order.vue')
	},
	{
		path:'/order-info',
		name:'order-info',
		component:() => import('@/views/me/order-info.vue')
	},
	{
		path:'/user-activity',
		name:'user-activity',
		component:() => import('@/views/me/user-activity.vue')
	}
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next) => {
	if(to.path!='/login'&&to.path!='/register'){
		let token = sessionStorage.token
		if(!!token == false){
			Toast.fail("您还没有登陆,\n请登陆")
			next('/login')
		}else{
			next()
		}
		
	}else{
		next()
	}
	
})
export default router
